using System;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Markup.Xaml;
using Avalonia.Media;
using Prism.Dialogs;
using Prism.Mvvm;

namespace JMClient.Views;

public partial class SandboxDialogWindow : Window, IDialogWindow
{
    public IDialogResult? Result { get; set; }
    public SandboxDialogWindow( )
    {
         
        this.Opened += OnOpened;
        InitializeComponent();
    }
    private void OnOpened(object? sender, EventArgs e)
    {
        if (this.DataContext is IDialogAware vm &&
            vm is IParameterReceiver receiver )
        {
            var parameters = receiver.DialogParameters;

            if (parameters.ContainsKey("width"))
                this.Width = parameters.GetValue<double>("width");

            if (parameters.ContainsKey("height"))
                this.Height = parameters.GetValue<double>("height");

            if (parameters.ContainsKey("title"))
                this.Title = parameters.GetValue<string>("title");

            this.WindowStartupLocation = WindowStartupLocation.CenterScreen;
            this.Topmost = true;

        }
    }
    public interface IParameterReceiver
    {
        DialogParameters DialogParameters { get; set; }
    }

}